#include "../../include/chat_tool.h"
void chatroom_tool::accept_friend_query(int fd, string data)
{
    string add_user,user_name,add_user_name;
    Json::Reader read;
    Json::Value te,root;
    if(!read.parse(data,te))
    {
        cout<<"json格式错误"<<endl;
        return;
    }
    if(te.isMember("add_user"))
    {
        add_user=te["add_user"].asString();
    }
    user_name=gun_like.user_search(fd);
    string temp="update relationship set relationship_status=1 where user_id_1='' and user_id_2='';";
    user_name=Mysql.user_search(user_name);
    add_user=Mysql.user_search(add_user);
    temp.insert(63,user_name);
    temp.insert(80+user_name.size(),add_user);
    if(!Mysql.no_result(temp))
    {
        cout<<"好友请求接受失败"<<endl;
    }
    else
    {
        root["status"]="new_friend_result_ok";
        root["add_user_name"]=add_user_name;
    }
    temp=root.toStyledString();
    send(fd,temp.c_str(),temp.size(),0);
}